package thread;

import java.util.concurrent.Semaphore;

public class Demo37 {
    public static void main(String[] args) throws InterruptedException {
        //Semaphore指信号量
        // 可用资源的个数. 计数器的初始值.
        Semaphore semaphore = new Semaphore(3);

        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.release();
        System.out.println("释放一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
    }
}